// 依赖库
import {createApp, Directive} from 'vue'
import ElementPlus from "element-plus";
import * as ElementPlusIcons from "@element-plus/icons-vue"; // 图标
import {createPinia} from "pinia"; // 状态管理
import "virtual:svg-icons-register";
import VMdEditor from "@kangc/v-md-editor";
import Prism from "prismjs";
import piniaPlugin from "pinia-plugin-persistedstate"; // 提供Pinia状态持久化功能
import createEmojiPlugin from "@kangc/v-md-editor/lib/plugins/emoji/index";
import createTodoListPlugin from "@kangc/v-md-editor/lib/plugins/todo-list/index";

// 文件或组件引入
import "@/permission";
import App from './App.vue'
import router from "@/router";
import * as directive from "@/directive"; // 自定义组件
import SvgIcon from "@/components/SvgIcon/index.vue";
import CalendarHeatmap from "@/components/CalendarHeatmap/index.vue";
import Echarts from "@/components/Echarts/index.vue";
import Pagination from "@/components/Pagination/index.vue";
import RightToolbar from "@/components/RightToolbar/index.vue";


// 样式文件
import "@/assets/styles/index.scss";
import "element-plus/theme-chalk/index.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import "viewerjs/dist/viewer.css";
import "nprogress/nprogress.css";
import "@kangc/v-md-editor/lib/plugins/emoji/emoji.css";
import "@kangc/v-md-editor/lib/plugins/todo-list/todo-list.css";
import "@kangc/v-md-editor/lib/style/base-editor.css";
import "@kangc/v-md-editor/lib/theme/style/vuepress.css";

import vuepressTheme from "@kangc/v-md-editor/lib/theme/vuepress.js";

const pinia = createPinia();
const app = createApp(App);

// 将directive对象中的所有自定义指令注册到Vue应用程序中
Object.keys(directive).forEach((key) => {
    app.directive(key, (directive as { [key: string]: Directive })[key]);
});

// 每个图标组件调用 app.component 方法注册为全局组件
for (const [key, component] of Object.entries(ElementPlusIcons)) {
    app.component(key, component);
}

// 注册库

pinia.use(piniaPlugin); // 状态持久,将状态保存到本地存储中，并在重新加载应用程序时，从本地存储中恢复状态
// 使用vuepressTheme主题、Prism语法高亮插件、createEmojiPlugin表情插件和createTodoListPlugin任务列表插件
VMdEditor.use(vuepressTheme, {Prism}).use(createEmojiPlugin()).use(createTodoListPlugin());
app.use(pinia);
app.use(ElementPlus);
app.use(router);
app.use(VMdEditor);
app.component("svg-icon", SvgIcon);
app.component("CalendarHeatmap", CalendarHeatmap);
app.component("Echarts", Echarts);
app.component("Pagination", Pagination);
app.component("RightToolbar", RightToolbar);

app.mount("#app");
